<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>用户管理编辑</title>
</head>
<jsp:include page="/common/meta.jsp"></jsp:include>
<jsp:include page="/common/resource.jsp"></jsp:include>
<script type="text/javascript">
/** 关闭窗口*/
	function dialogClose() {
		//关闭自己
		if ($.easyui.showDialog.parent.doSearch) {
			$.easyui.showDialog.parent.doSearch();
		} else {
			$.easyui.showDialog.parent.location.reload();
			//刷新父页面
		}
		$.easyui.showDialog.parent.easyuiDialog.close();
	}
	debugger;
/* 获取放到作用域的值**/
var  editEntity =${editEntity};
$(function(){
    /* 初始化选择员工*/
    initUserVOTextBox();
    /* 初始化选择部门*/
    initOrgCombotree();
    /** 初始化角色的checkbox*/
    $(".rolesCheckBox").checkbox({});
    /** 初始化头像文件*/
    $('#icon').filebox({
        buttonText: '选择文件',
        width:177
    })

});

/** 初始化员工textbox*/
function  initUserVOTextBox() {
    $('#staff_VO').textbox({
        icons: [{
            iconCls:'icon-search',
            handler: function(e){
                var inputID = e.data.target.id;
                /** 调用员工页面接口*/
                searchStaff(inputID);
            }
        }]
    });
}
/* 打开查询员工窗口**/
function searchStaff(inputID){
    /** 去查询员工窗口*/
    var url = "${base}/hr/staff/StaffController/goStaffPage?inputID="+inputID;
    openEasyuiDialog("员工列表", url, 600, 500);
}
/** 设置值*/
function confirmReturn(obj){
    var inputID = obj.inputID;
    if("staff_VO" == inputID ){
        $("#staff_VO").textbox("setValue","小红")
        $("representative").val("1");
    }
}
/* 初始化组织机构树**/
function initOrgCombotree() {
    $("#org_id_VO").combotree({
        url: '${base}/hr/organization/OrganizationController/listQueryCompanyOrganizationTreeNode',
        required: true,
        novalidate:'true',
        missingMessage:'请选择组织机构',
        onClick: function(node){
            var company_id = node.attributes.company_id;
            var org_id =  node.attributes.org_id;
            /* 设置组织机构id**/
            $("#org_id").val(org_id);
            /* 设置企业会员id**/
            $("#company_org_id").val(company_id);
        },
        onLoadSuccess:function (node, data){
            $("#org_id_VO").combotree('setValue', editEntity.org_id);

        }

    });
}

    /** 保存方法*/
    function doSave() {
        /**验证数据**/
        if (!ValidateForm("#User_edit_form")) {
            return;
        }
        var roles = $(".rolesCheckBox").checkbox("getValues");
        /* 判断是否选中角色*/
        if(roles.length == 0){
            top.$.messager.alert('提示', "请选择角色", 'info');
            return;
        }
        /* 给角色赋值**/
        $("#rolesIdList").val(roles);
        var formData = new FormData($( "#User_edit_form" )[0]);
        $.ajax({
            url: "${base}/system/user/UserController/update",
            data: formData,
            type: "POST",
            dataType: "JSON",
            contentType: false,
            processData: false,
            cache: false,
            beforeSend: function (xhr) {
            	/** 开启遮罩层次*/
                $.easyui.loading({ msg: "请稍候...",topMost :true });
            },
            complete: function (xhr, ts) {
            	/** 关闭遮罩层*/
                $.easyui.loaded({topMost :true});
            },
            success: function (data) {

                var flag = data.flag;
                if (flag) { //验证成功
                    top.$.messager.alert('提示', "修改成功", 'info', function () {
                        dialogClose();
                    });
                } else { //验证失败
                    var msg = data.msg;
                    top.$.messager.alert('修改失败', msg, 'error');
                }
            }
        });
    }
</script>
<body>
<div id="User_edit_div" class="form-box" style="padding-top:10px;height: 85% ">
	<!-- form-box begin -->
	<form id="User_edit_form"  enctype="multipart/form-data">
    	<jsp:include page="vo/editVO.jsp"></jsp:include>
	</form>
	<!-- form-box end -->
</div>	
<div id="childButtons" style=" margin-right: 10px;text-align: right;">
    <a href="javascript:void(0)" class="easyui-linkbutton button-blue l-btn l-btn-small" id="save" onclick="doSave()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton button-red l-btn l-btn-small" id="close" onclick="dialogClose()">关闭</a>
</div>
</body>
</html>
<script type="text/javascript">
	$(function(){
		$.fn.form.methods.enableAutoFocus($("#User_add_div"));
	});
</script>